package com.linxz.ui.widgets.images;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.linxz.framework.protocol.image.ImageHelper;
import com.linxz.ui.R;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Linxz
 * 创建日期：2020年02月05日 17:05
 * version：v4.5.4
 * 描述：
 */
public class DynamicImageLayout extends FrameLayout {

    private List<String> images=new ArrayList<>();

    public DynamicImageLayout(@NonNull Context context) {
        super(context);
    }

    public DynamicImageLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DynamicImageLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    public void setImages(List<String> images){
        this.images.addAll(images);
        initUI();
    }

    private void initUI(){
        switch (images.size()){
            case 0:
                break;
            case 1:
                createOneUI();
                break;
            case 2:
                createTwoUI();
                break;
            case 3:
                createThreeUI();
                break;
            case 4:
                createFourUI();
                break;
            case 5:
                createFiveUI();
                break;
            case 6:
                createSixUI();
                break;
            default:
                createOtherUI();
                break;
        }
    }

    private void createOneUI(){
        LayoutInflater.from(getContext()).inflate(R.layout.ui_dynamic_image_layout_one,this);
        ImageView[] imageViews=new ImageView[images.size()];
        imageViews[0]=findViewById(R.id.imageOne);
        for (int i=0;i<imageViews.length;i++){
            ImageHelper.imageNet(getContext(),images.get(i),imageViews[i]);
        }
    }


    private void createTwoUI(){
        LayoutInflater.from(getContext()).inflate(R.layout.ui_dynamic_image_layout_two,this);
        ImageView[] imageViews=new ImageView[images.size()];
        imageViews[0]=findViewById(R.id.imageOne);
        imageViews[1]=findViewById(R.id.imageTwo);
        for (int i=0;i<imageViews.length;i++){
            ImageHelper.imageNet(getContext(),images.get(i),imageViews[i]);
        }
    }


    private void createThreeUI(){
        LayoutInflater.from(getContext()).inflate(R.layout.ui_dynamic_image_layout_three,this);
        ImageView[] imageViews=new ImageView[images.size()];
        imageViews[0]=findViewById(R.id.imageOne);
        imageViews[1]=findViewById(R.id.imageTwo);
        imageViews[2]=findViewById(R.id.imageThree);
        for (int i=0;i<imageViews.length;i++){
            ImageHelper.imageNet(getContext(),images.get(i),imageViews[i]);
        }
    }


    private void createFourUI(){
        LayoutInflater.from(getContext()).inflate(R.layout.ui_dynamic_image_layout_four,this);
        ImageView[] imageViews=new ImageView[images.size()];
        imageViews[0]=findViewById(R.id.imageOne);
        imageViews[1]=findViewById(R.id.imageTwo);
        imageViews[2]=findViewById(R.id.imageThree);
        imageViews[3]=findViewById(R.id.imageThour);
        for (int i=0;i<imageViews.length;i++){
            ImageHelper.imageNet(getContext(),images.get(i),imageViews[i]);
        }
    }


    private void createFiveUI(){
        LayoutInflater.from(getContext()).inflate(R.layout.ui_dynamic_image_layout_five,this);
        ImageView[] imageViews=new ImageView[images.size()];
        imageViews[0]=findViewById(R.id.imageOne);
        imageViews[1]=findViewById(R.id.imageTwo);
        imageViews[2]=findViewById(R.id.imageThree);
        imageViews[3]=findViewById(R.id.imageThour);
        imageViews[4]=findViewById(R.id.imageFive);
        for (int i=0;i<imageViews.length;i++){
            ImageHelper.imageNet(getContext(),images.get(i),imageViews[i]);
        }
    }


    private void createSixUI(){
        LayoutInflater.from(getContext()).inflate(R.layout.ui_dynamic_image_layout_six,this);
        ImageView[] imageViews=new ImageView[images.size()];
        imageViews[0]=findViewById(R.id.imageOne);
        imageViews[1]=findViewById(R.id.imageTwo);
        imageViews[2]=findViewById(R.id.imageThree);
        imageViews[3]=findViewById(R.id.imageThour);
        imageViews[4]=findViewById(R.id.imageFive);
        imageViews[5]=findViewById(R.id.imageSix);
        for (int i=0;i<imageViews.length;i++){
            ImageHelper.imageNet(getContext(),images.get(i),imageViews[i]);
        }
    }


    private void createOtherUI(){
        LayoutInflater.from(getContext()).inflate(R.layout.ui_dynamic_image_layout_other,this);
        MultiImageView multiIV=findViewById(R.id.multiIV);
        multiIV.setList(images);
    }



}
